var server = require('./utils/server');
App({
	onLaunch: function () {
    
	},
 onLoad:function(){
 
 },
  
	globalData: {
		hasLogin: false,
    preUrl:"https://www.xpping.com",
		shops: [
			 
		]
	},
	rd_session: null,
	login: function() {
		var self = this;
		wx.login({
			success: function (res) {
	     console.log(res);
			 	// server.getJSON('/WxAppApi/setUserSessionKey', {code: res.code}, function (res) {
				// 	console.log('setUserSessionKey', res)
				// 	self.rd_session = res.data.data.rd_session;
				// 	self.globalData.hasLogin = true;
				// 	wx.setStorageSync('rd_session', self.rd_session);
				// 	self.getUserInfo();
				// });
			}
		});
	},
	getUserInfo: function() {
		var self = this;
		wx.getUserInfo({
			success: function(res) {
        console.log(res);
        self.globalData.userInfo = res.userInfo;
				server.getJSON('/WxAppApi/checkSignature', {
					rd_session: self.rd_session,
					result: res
				}, function (res) {
					console.log('checkSignature', res)
					if (res.data.errorcode) {
						// TODO:验证有误处理
					}
				});
			}
		});
	}
})
